package www.xudan.javabasedemo.model.Proxy.DynamicsProxy.vertical;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by ${XuDan} on 2020/3/23.
 * 1.实现InvocationHandler接口
 * 2.持有真实类对象
 */
public class VerticalProxy implements InvocationHandler {

    private ZuFang zuke;

    public VerticalProxy(ZuFang zuke) {
        this.zuke = zuke;
    }

    /**
     * @param proxy  代理类
     * @param method 方法
     * @param args   方法参数
     * @return
     * @throws
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object obj = null;
        switch (method.getName()) {
            case "findfangzi":
                System.out.println("我是代理类:我可以找房子");
                break;
            case "zufang":
                obj = method.invoke(zuke, args);
                obj=(int)obj-200;
                break;
            case "hetong":
                System.out.println("我是代理类:我准备合同");
                break;
        }
        return obj;
    }
}
